﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Cesave.Domain.PermisosModule.Contracts.Concesiones;
using Cesave.Infrastructure.CrossCutting.IoC;
using Cesave.Domain.PermisosModule.Entities;
using Cesave.Domain.Core;

namespace Cesave.Domain.PermisosModule.Tests.ServicesTests
{
	[TestClass]
	[DeploymentItem("Cesave.Infrastructure.Data.PermisosModule.Mock.dll")]
	[DeploymentItem("Cesave.Infrastructure.Data.PermisosModule.dll")]
	public class ConcesionServiceTests
	{
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void AddConcesion_Null_Concesion_Throws_ArgumentException()
		{
			// Arrange
			IConcesionService service = IoCFactory.Resolve<IConcesionService>();

			// Act
			service.AddConcesion(null);
		}

		[TestMethod]
		public void AddConcesion_Invoke()
		{
			// Arrange
			IConcesionService service = IoCFactory.Resolve<IConcesionService>();
			IConcesionRepository repository = IoCFactory.Resolve<IConcesionRepository>();

			var guid = Guid.NewGuid();

			var expected = new Concesion
			{
				ConcesionGuid = guid,
				ConcesionId = 99,
				Nombre = "TEST",
				Status = true,
			};

			// Act
			service.AddConcesion(expected);

			var actual = service.FindConcesionByGuid(guid);

			// Assert
			Assert.IsNotNull(actual);
			Assert.AreEqual("TEST", actual.Nombre);

			// clean
			IUnitOfWork unitOfWork = repository.StoreContext;
			repository.Remove(actual);
			unitOfWork.Commit();
			Assert.IsNull(service.FindConcesionByGuid(guid));
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void ChangeConcesion_Null_Concesion_Throws_ArgumentNullException()
		{
			// Arrange
			IConcesionService service = IoCFactory.Resolve<IConcesionService>();

			// Act
			service.ChangeConcesion(null);
		}

		[TestMethod]
		public void ChangeConcesion_Invoke()
		{
			// Arrange
			IConcesionService service = IoCFactory.Resolve<IConcesionService>();

			var guid = new Guid("1BA4123A-2F47-4303-B4C2-8DD72FA15AA8");
			var expected = service.FindConcesionByGuid(guid);
			expected.Descripcion = "TEST";

			// Act
			service.ChangeConcesion(expected);

			var actual = service.FindConcesionByGuid(guid);

			// Assert
			Assert.AreEqual(expected, actual);
		}
	}
}